import Stack from "./Stack";

class ArrayStack<T> implements Stack<T> {
  private data: T[] = [];

  size(): number {
    return this.data.length;
  }

  isEmpty(): boolean {
    return this.size() === 0;
  }

  push(element: T) {
    this.data.push(element);
  }

  pop(): T | undefined {
    return this.data.pop();
  }

  peek(): T | undefined {
    return this.data[this.size() - 1];
  }

  toString(): string {
    return this.data.reduce((pre, cur) => (pre += cur + " "), "");
  }
}

export default ArrayStack;
export {};
